package jt.classic.app.gdzc.baofei;

import org.limp.basework.MachiningException;
import org.limp.basework.SimpleBean;
import org.limp.basework.SimpleBean4Table;
import org.limp.basework.SimpleBeanMachining;
import org.limp.basework.Table;
import org.limp.basework.impl.SimpleBean4TableImpl;
import org.limp.basework.tools.BaseworkUtil;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;


public class BaofeiMachining implements SimpleBeanMachining {
    public SimpleBean machining(SimpleBean bean, Table table,
        HttpServletRequest request, Connection conn, int type)
        throws MachiningException {
        // TODO Auto-generated method stub

        /*资产报废登记*/
        if (table.getName().equals("APP_GDZC_BAOFEI") && (type == 0)) {
            String gzid = (String) bean.getResource().get("GZID");

            SimpleBean4Table sbt = new SimpleBean4TableImpl("APP_GDZC");
            sbt.getResource().put("GZID", gzid);
            sbt.getResource().put("GZSTATUS", "-1");

            BaseworkUtil util = new BaseworkUtil();

            try {
                util.manualUpdate1(sbt, conn);
            } catch (Exception ex) {
                throw new MachiningException("Baofei machining error.", ex);
            }
        }
        /*资产报废审核*/
        else if (table.getName().equals("APP_GDZC_BAOFEI") && (type == 1)) {
            String gzid = (String) bean.getResource().get("GZID");
            String status = (String) bean.getResource().get("BFSTATUS");

            if (status.equals("-1")) {
                SimpleBean4Table sbt = new SimpleBean4TableImpl("APP_GDZC");
                sbt.getResource().put("GZID", gzid);
                sbt.getResource().put("GZSTATUS", "0");

                BaseworkUtil util = new BaseworkUtil();

                try {
                    util.manualUpdate1(sbt, conn);
                } catch (Exception ex) {
                    throw new MachiningException("Baofei machining error.", ex);
                }
            }
        }

        return null;
    }
}
